package Week5.J0514;

// 要么2, 要么3, 要么-1

import java.util.Scanner;

public class 小红的ABC {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        char[] s = scanner.next().toCharArray();

        for (int i = 1; i < s.length; i++) {
            if (s[i] == s[i-1]) {
                System.out.println(2);
                return;
            }
        }

        for (int i = 2; i < s.length; i++) {
            if (s[i] == s[i-2]) {
                System.out.println(3);
                return;
            }
        }

        System.out.println(-1);
    }
}
